#----------------------------
# Name: brandon butcher
# Project: Madlibs.py
# Period: 2
# Start Date: 9/17/2013
# Last Revision Date: 9/17/2013
# Version: 1.0.0
#----------------------------

swearFilter = ["dumb",
               "stupid",
               "retard",
               "fuck",
               "pussy",
               "cock",
               "penis",
               "ass",
               "cunt",
               "fucked",
               "raped",
               "hell"'
               "God,"
               "Travis,"
               "Islam,"
               "Christianity,"
               "Judaism,"
               "dammit,"
               "nigger,"
               "fucking,"]               ]

def displayStartScreen():
    print "Madlibs"
    raw_input("Press Enter to Continue")
    
def displayEndScreen():
    print "Goodbye"
    raw_input("Press Enter to Exit")

def getMenuOption(maxOption):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter Number or Q or S>")
        option = option.upper()
        for num in range(1, maxOption+3):
            if option == str(num):
                goodOption = True
        if option == 'Q':
            goodOption = True
        if option == 'S':
            goodOption = True
        if not goodOption:
            print "Please pick a valid option!"
    return option
        
def menu(options):
    print "------Please Select a Story------"
    print " [1] The End of the Day"
    print " [2] A couple new friends at school"
    print " [3] Sky Diving"
    print " [Q] Quit"
    print " [S] Settings"
    print "----------------------------------"
    option = getMenuOption(options)
    return option
    
 

# will-anderson-madlibs
# William Anderson
# https://code.google.com/p/will-anderson-madlibs/
# Version: https://code.google.com/p/will-anderson-madlibs/source/detail?r=ba82c1ba90f9eb88fa75cc2e2eb3950a0d8db7b4
def getColor(prompt):
        colors = ["black",
                          "blue",
                          "green",
                          "aqua",
                          "red",
                          "purple",
                          'yellow',
                          'white',
                          'gray',
                          'light blue',
                          'light green',
                          'light aqua',
                          'light red',
                          'light purple',
                          'light yellow',
                          'bright white']
        opt = ""
        goodColor = False
        while not goodColor:
                opt = raw_input(prompt)
                if opt.lower() in colors:
                        goodColor = True
        if opt == "black":
                color = '0'
        elif opt == 'blue':
                color = '1'
        elif opt == 'green':
                color = '2'
        elif opt == 'aqua':
                color = '3'
        elif opt == 'red':
                color = '4'
        elif opt == 'purple':
                color = '5'
        elif opt == 'yellow':
                color = '6'
        elif opt == 'white':
                color = '7'
        elif opt == 'gray':
                color = '8'
        elif opt == 'light blue':
                color = '9'
        elif opt == 'light green':
                color = 'A'
        elif opt == 'light aqua':
                color = 'B'
        elif opt == 'light red':
                color = 'C'
        elif opt == 'light purple':
                color = 'D'
        elif opt == 'light yellow':
                color = 'E'
        elif opt == 'bright white':
                color = 'F'
        
        return color

def settings():
        txtColor = getColor('Enter Text Color.\nColors are:\nblack\nblue\ngreen\naqua\nred\npurple\nyellow\nwhite\ngray\nlight blue\nlight green\nlight aqua\nlight red\nlight purple\nlight yellow\nbright white')
        bgColor = getColor('Enter Backgound Color:.\nColors are:\nblack\nblue\ngreen\naqua\nred\npurple\nyellow\nwhite\ngray\nlight blue\nlight green\nlight aqua\nlight red\nlight purple\nlight yellow\nbright white')
        if txtColor != bgColor:
                os.system("color " + bgColor + txtColor)
 
def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearFilter:
            goodWord = True
        else:
            print "Naughty player...please be polite."
        if not goodWord:
            print "Try again"
    return word
    
def getNumber(prompt, max = "", min = ""):


    num = ""
    goodNum = False
    while not goodNum:
        isNum = True
        num = raw_input(prompt)
        for character in num:
            if character not in "0123456789":
                isNum = False
        if min != "":
            if isNum:
                if float(num) < min:
                    isNum = False
        if max != "":
            if isNum:
                if float(num) > max:
                    isNum = False
        if isNum:
            goodNum = True
        else:
            print "Not a valid number, try again."
    return num
    
def story1():
    place1 = getWord("Enter a place: ")
    story = "It was near the end of the day in"
    story += " " + place1 + ", suddenly"    
    name1 = getWord("Enter a name: ")
    story += " " + name1 + ", walked up to"
    name2 = getWord("Enter a name: ")
    story += " " + name2 + ", and"
    verb1 = getWord("enter a verb in past tense: ")
    story += " " + verb1
    story += ", the end"
    
    print story
    print
def story2():
    name = getWord("Enter a name: ")
    name1 = getWord("Enter a name: ")
    name2 = getWord("Enter a name: ")
    age = getNumber("Enter a number: ")
    verb = getWord("Enter a verb: ")
    day1 = getWord("Enter a day: ")
    name3 = getWord("Enter an important person: ")
    verb2 = getWord("Enter another verb: ")
    story = "I met some guys and their names are"
    story += " " + name +" " + name1 + " " + name2 + " "
    story += "I think " + "they are" + " " + age
    story += " years old" + " "
    story += name + " " + verb + " " + "in the school" + " "
    story += "yesterday" + " " + "was" + " " + day1
    story += name3 + " " + "told him to" + " " + verb2
    story += " The End"
    
    print story
def story3():

    name1 = getWord("Enter a name: ")
    place1 = getWord("enter a place: ")
    story = name1 + " was walking down the road"
    story += " and got into the air plane" + place1
    
    print story
def run():
    displayStartScreen()
    choice = ""
    while choice != 'Q':
        choice = menu(2)
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'S':
            displaysettings()
        elif choice == 'Q':
            displayEndScreen()
        else:
            print "Something Awful Occurred...yell at programmer!"
    exit()
    
run()